package com._58city.spark.app.ext;

import java.lang.reflect.Method;

public class BaseUtility {
	private volatile Class<?> toolClass ;
	private volatile Object toolInstance ;
	private volatile Method toolMethod ;
	
	public BaseUtility(Class<?> toolClass) throws Exception{
		super();
		this.toolClass = toolClass;
		this.toolInstance = toolClass.newInstance();
		this.toolMethod = toolClass.getDeclaredMethod("toolMethod",String.class);
		this.toolMethod.setAccessible(true);
	}
	
	public Object analyse(String input) {
		try {
			return toolMethod.invoke(toolInstance, input);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public Class<?> getToolClass() {
		return toolClass;
	}
	
	public void setToolClass(Class<?> toolClass) {
		this.toolClass = toolClass;
	}
	
	public Object getToolInstance() {
		return toolInstance;
	}
	
	public void setToolInstance(Object toolInstance) {
		this.toolInstance = toolInstance;
	}
	
	public Method getToolMethod() {
		return toolMethod;
	}
	
	public void setToolMethod(Method toolMethod) {
		this.toolMethod = toolMethod;
	}

}
